// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 *
 * @author: yanking
 * Create time: 2022-04-11 14:22
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.CountPrimeByStream;

import java.util.stream.IntStream;

@SuppressWarnings("ALL")
public class countPrimeByStream {
    static IntStream number() {
        return IntStream.iterate(2, i -> i + 1);
    }

    static int head(IntStream numbers) {
        return numbers.findFirst().getAsInt();
    }

    static IntStream tail(IntStream numbers) {
        return numbers.skip(1);
    }

    static IntStream primes(IntStream numbers) {
        int head = head(numbers);
        return IntStream.concat(IntStream.of(head), primes(tail(numbers).filter(i -> i % head != 0)));
    }

    public static void main(String[] args) {
        primes(number()).forEach(System.out::println);
    }


}
